//
//  ComposeTextView.swift
//  ZMWEIBO
//
//  Created by 庄猛 on 17/1/11.
//  Copyright © 2017年 BeiSheng. All rights reserved.
//

import UIKit

class ComposeTextView: EmoticonTextView {

    override init(frame: CGRect, textContainer: NSTextContainer?) {
    super.init(frame: frame, textContainer: textContainer)
        addSubview(placeholder)
        
        NotificationCenter.default.addObserver(self, selector: #selector(textChange), name: NSNotification.Name.UITextViewTextDidChange, object: self)
        

    }

    deinit {
        
        NotificationCenter.default.removeObserver(self)
    }
    
    
    @objc func textChange(){
        
        placeholder.isHidden = hasText
        
        
    }

    override var font: UIFont?{
        
        didSet{
            
            placeholder.font = font
            placeholder.sizeToFit()
            placeholder.frame.origin.x = 5
            placeholder.frame.origin.y = 8
            placeholder.numberOfLines = 0
            placeholder.frame.size.width = KScreenW - 10
            placeholder.sizeToFit()

            
        }

    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        addSubview(placeholder)
        
        NotificationCenter.default.addObserver(self, selector: #selector(textChange), name: NSNotification.Name.UITextViewTextDidChange, object: self)
        

    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    lazy var placeholder : UILabel = {
        let temp = UILabel()
        temp.text = "请详细描述您要出租(求租)的房屋(车位)信息,并附上联系方式和称呼..."
        temp.textColor = UIColor.lightGray
        return temp
    }()
    

}
